00001
00005 class CarPhysics : public PhysicsClient
00006 {
00007 public:
00012 CarPhysics(Vehicle& vehicle);
00016 virtual ~CarPhysics();
00017
00022 virtual double update(double step);
00027 virtual void odeDraw();
00036 bool create( const CarData* carDataPtr,osg::ref_ptr<osg::PositionAttitudeTransform> objectPAT );
00037 void setSteering(double steer) { _steering = steer; }
00038 void setAccelleration(double acl) { _accel = acl; }
00039 void setGear(int gear);
00040
00041 double getSpeed();
00042 double getTraction() { return _traction; }
00043 const Vector3& getPosition();
00044 const double* getRotation();
00045
00046 void setPosition(double x, double y, double z);
00047 void setRotation(double x, double y, double z);
00048 void mySetPosition();
00049 Vehicle* getOSGVehicle();
00050 protected:
00058 void positionCar(double x, double y, double z);
00065 const double* getGeomPosition(dGeomID geom);
00066 const double* getGeomRotation(dGeomID geom);
00067
00068
00069 void addGeom(dGeomID geom, dReal xoff, dReal yoff, dReal zoff, dMatrix3 R);
00070
00071
00072
00073 protected:
00078 const CarData* _pCarData;
00083 double _steering;
00088 double _accel;
00093 double _speed;
00094
00095 double _traction;
00100 double _chassisHgt;
00105 double _gearMod;
00106
00112 dBodyID _carBody;
00117 dBodyID _wheelBody[4];
00118
00123 dJointID _joint[4];
00124
00129 dSpaceID _carSpace;
00134 vector<dGeomID> _carGeoms;
00139 dGeomID _wheelGeom[4];
00140 PhysGeomData _wheelData;
00141 Vehicle OSGvehicle;
00142 };
00143
00144 class PhysicsEventHandler: public osgGA::GUIEventHandler
00145 {
00146 public:
00147 PhysicsEventHandler (osg::ref_ptr<osgProducer::Viewer> viewer)
00148 : viewer_(viewer),_throttleSet(false),_brakeSet(false),_steerLeftSet(false),_steerRightSet(false),_stop(false)
00149 { }
00150
00151 ~PhysicsEventHandler() { }
00152
00153 bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa);
00154
00155 virtual void accept(osgGA::GUIEventHandlerVisitor& v)
00156 {
00157 v.visit(*this);
00158 }
00159 bool _throttleSet;
00160 bool _brakeSet;
00161 bool _steerLeftSet;
00162 bool _steerRightSet;
00163 bool _stop;
00164 private:
00165 osg::ref_ptr<osgProducer::Viewer> viewer_;
00166 osg::ref_ptr<osg::Group> root;
00167
00168 };